// 引入mockjs
const Mock = require('mockjs')
// 获取 mock.Random 对象
// 参考：https://github.com/nuysoft/Mock/wiki/Mock.Random
const Random = Mock.Random
let Result = {
    code: 200,
    msg: '操作成功',
    data: null
}
/**
 * Mock.mock( url, post/get , function(options))；
 * url 表示需要拦截的 URL，
 * post/get 需要拦截的 Ajax 请求类型
 *
 * 用于生成响应数据的函数
 */

// 获取验证码图片base64编码以及一个随机码
Mock.mock('/captcha', 'get', () => {
    Result.data = {
        token: Random.string(32), // 获取一个32位的随机字符串,
        captchaImg: Random.dataImage("120x40", "11111") //生成验证码为11111的base64图片编码
    }
    return Result
})

// 因为mock不认识/login?username=xxx，所以用了正则表达式
Mock.mock(RegExp('/admin*'), 'post', (config) => {
    // 这里无法在header添加authorization，直接跳过
    //console.log("mock----------------login")
    return Result
})

//测试管理员数据
Mock.mock('/sys/userInfo', 'get', () => {
    Result.data = {
        id: "1",
        username: "leeion",
        avatar: "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg"
    }
    return Result
})

//模拟文章数据
Mock.mock(RegExp('/sys/news/list*'), 'get', () => {
    Result.data = {
        "records": [
            {
                "id": 01,
                "title": '路上看见达拉斯来得及',
                "createtime": '2021-11-21',
                "updatetime": '2021-11-27'
            },
            {
                "id": 02,
                "title": '路上看见达拉斯来得及',
                "createtime": '2021-11-21',
                "updatetime": '2021-11-27'
            },
            {
                "id": 03,
                "title": '路上看见达拉斯来得及',
                "createtime": '2021-11-21',
                "updatetime": '2021-11-27'
            },
        ],
        "total": 3,
        "size": 10,
        "current": 1,
        "orders": [],
        "optimizeCountSql": true,
        "hitCount": false,
        "countId": null,
        "maxLimit": null,
        "searchCount": true,
        "pages": 1
    }
    return Result
})

Mock.mock(RegExp('/sys/news/*'), 'post', () => {
    return Result
})

//正则判断
Mock.mock(RegExp('/sys/news/info/*'), 'get', () => {
    Result.data = {
        "id": 1,
        "title": "全欧韦克斯端口进行操作",
        "description": "阿拉斯加杜拉拉就是领导最新批次啊啊十大科技卡就问你静安寺破i皮鞋再次离开埃里克时间来得及啦",
        "content": "## description 水水水水"
    }
    return Result
})


////////////////////     用  户    /////////////////////////

//模拟用户数据
Mock.mock(RegExp('/sys/user/list/*'), 'get', () => {
    Result.data = {
        "records": [
            {
                "uid": 2,
                "nickname": '李航',
                "username": 'lihang',
                "phone": '15813256250',
                "email": '1400510235@qq.com',
                "createtime": "2021-05-04",
            },
            {
                "uid": 3,
                "nickname": '李航',
                "username": 'lihang',
                "phone": '15813256250',
                "email": '1400510235@qq.com',
                "createtime": "2021-05-04",
            },
            {
                "uid": 4,
                "nickname": '李航',
                "username": 'lihang',
                "phone": '15813256250',
                "email": '1400510235@qq.com',
                "createtime": "2021-05-04",
            },
        ],
        "total": 3,
        "size": 10,
        "current": 1,
        "orders": [],
        "optimizeCountSql": true,
        "hitCount": false,
        "countId": null,
        "maxLimit": null,
        "searchCount": true,
        "pages": 1
    }

    return Result
})

//要修改的用户信息
Mock.mock(RegExp('/sys/user/info/*'), 'get', () => {
    Result.data = {
        "uid": 2,
        "nickname": '李航',
        "username": 'lihang',
        "phone": '15813256250',
        "email": '1400510235@qq.com',
        "createtime": "2021-05-04",
    }
    return Result
})

//正则判断
Mock.mock(RegExp('/sys/user*'), 'post', () => {
    return Result
})

